using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class AssemblyMap : EntityTypeConfiguration<Assembly>
    {
        public AssemblyMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.KIT)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.TYPE)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(10);

            this.Property(t => t.LOCATION)
                .IsRequired()
                .HasMaxLength(3);

            this.Property(t => t.NOTE)
                .HasMaxLength(50);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Assembly");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.KIT).HasColumnName("KIT");
            this.Property(t => t.DATE).HasColumnName("DATE");
            this.Property(t => t.QTY).HasColumnName("QTY");
            this.Property(t => t.TYPE).HasColumnName("TYPE");
            this.Property(t => t.LOCATION).HasColumnName("LOCATION");
            this.Property(t => t.BARCODEPRINTED).HasColumnName("BARCODEPRINTED");
            this.Property(t => t.NOTE).HasColumnName("NOTE");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");

            // Relationships
            this.HasRequired(t => t.Item)
                .WithMany(t => t.Assemblies)
                .HasForeignKey(d => d.KIT);

        }
    }
}
